package cn.edu.scau.cmi.chenxiaoqin.hibernate.dao;

import org.hibernate.Session;
import org.hibernate.Transaction;

import cn.edu.scau.cmi.chenxiaoqin.hibernate.factory.*;
import cn.edu.scau.cmi.chenxiaoqin.hibernate.domain.*;

public class TeacherDao {
     private static String NAME="name";
     private static Session session=HibernateSessionFactory.getSession();
     
     public void save(Teacher ins)  //加入老师
     {
    	 try {
    		 Transaction transaction=session.beginTransaction();
    		 session.save(ins);
    		 transaction.commit();
    	 }
    	 catch(Exception e)
    	 {
    		 throw e;
    	 }
     }
     
     public void delete(Teacher ins)  //删除导师
     {
    	 try {
    		 Transaction transaction = session.beginTransaction();
    		 session.delete(ins);
    		 transaction.commit();
    	 }
    	 catch(Exception e)
    	 {
    		 throw e;
    	 }
     }
     
     public void update(Teacher ins)  //修改导师
     {
    	 try {
    		 Transaction transaction = session.beginTransaction();
    		 session.update(ins);
    		 transaction.commit();
    	 }
    	 catch(Exception e)
    	 {
    		 throw e;
    	 }
     }
     
     public Teacher getById(String id) {
  	   try {
  		   Teacher inTea=(Teacher)session.get("cn.edu.scau.cmi.chenxiaoqin.hibernate.domain.Teacher", id);
  		   return inTea;
  	   }
  	   catch(Exception e)
  	   {
  		   throw e;
  	   }
     }
     
     public void select(Teacher ins)
     {
    	 try {
  		   Transaction transation=session.beginTransaction();
  		   session.saveOrUpdate(ins);
  		   transation.commit();
  	   }
  	   catch(Exception e)
  	   {
  		   throw e;
  	   }
     }
}
